package com.zw.langchainai.config;

import com.zw.langchainai.repository.RedisChatMemoryStore;
import dev.langchain4j.memory.chat.ChatMemoryProvider;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 聊天记忆隔离对话智能体的配置类
 */
@Configuration
public class SeparateChatAssistantConfig {
    // 注入持久化对象
    @Autowired
    private RedisChatMemoryStore redisChatMemoryStore;

    /**
     * 创建一个ChatMemoryProvider对象
     */
    @Bean(name = "chatMemoryProvider")
    public ChatMemoryProvider chatMemoryProvider() {
        return messageId -> MessageWindowChatMemory.builder()
                .id(messageId)
                .maxMessages(10)
                .chatMemoryStore(redisChatMemoryStore) // 配置持久化
                .build();
    }
}
